const express = require('express')
const fs = require('fs')
const config = require(process.cwd() + '/src/config/config')
const Game = require(process.cwd() + '/src/class/index')

let router = express.Router()

const doAction = async (req) => {
  const env = new Game.Env()
  
  await env.init(req.body.env)
  
  env.setEnv(req.body.data)
  
  // 保存
  await env.save()
}

/* GET users listing. */
router.post('/', function (req, res) {
  doAction(req).then(() => {
    res.sendStatus(200)
  })
  .catch((err) => {
    console.log(err)
    res.sendStatus(500)
  })
})

module.exports = router
